package com.strange.mdl.module.mdl.controller.app.debatehall;

import com.strange.mdl.framework.common.pojo.CommonResult;
import com.strange.mdl.framework.common.pojo.PageResult;
import com.strange.mdl.framework.common.util.object.BeanUtils;
import com.strange.mdl.module.mdl.controller.admin.debatehall.vo.DebatehallPageReqVO;
import com.strange.mdl.module.mdl.controller.admin.user.vo.MdlUserRespVO;
import com.strange.mdl.module.mdl.dal.dataobject.debatehall.DebatehallDO;
import com.strange.mdl.module.mdl.dal.dataobject.debatehallcomment.DebatehallCommentDO;
import com.strange.mdl.module.mdl.dal.dataobject.user.MdlUserDO;
import com.strange.mdl.module.mdl.service.debatehall.DebatehallService;
import com.strange.mdl.module.mdl.service.debatehallcomment.DebatehallCommentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.annotation.security.PermitAll;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static com.strange.mdl.framework.common.pojo.CommonResult.success;

@Tag(name = "app-辨经殿话题")
@RestController
@RequestMapping("/mdl/appdebatehall")
@Validated
public class AppDebatehallController {

    @Resource
    private DebatehallService debatehallService;

    @Resource
    private DebatehallCommentService debatehallCommentService;
    @GetMapping("/page")
    @Operation(summary = "获得辨经殿话题分页")
    @PermitAll
    public CommonResult<PageResult<DebatehallDO>> page(@Valid DebatehallPageReqVO pageReqVO) {
        PageResult<DebatehallDO> pageResult = debatehallService.getDebatehallPage(pageReqVO);
        new PageResult<>(pageResult.getList(), pageResult.getTotal());
        return success(pageResult);
    }

    @GetMapping("/support")
    @Operation(summary = "支持辨经")
    @Parameter(name = "userId", description = "用户编号", required = true, example = "123456")
    @Parameter(name = "debateId", description = "辩经编号", required = true, example = "789012")
    @Parameter(name = "type", description = "支持类型", required = true, example = "1")
    @PermitAll
    public CommonResult<DebatehallDO> support(
            @RequestParam("userId") Long userId,
            @RequestParam("debateId") Long debateId,
            @RequestParam("type") Integer type) {
        DebatehallDO support = debatehallService.support(userId, debateId, type);
        return success(support);
    }


    @GetMapping("/operate")
    @Operation(summary = "操作点赞收藏评论分享状态")
    @Parameter(name = "userId", description = "用户编号", required = true, example = "123456")
    @Parameter(name = "debateId", description = "辩经编号", required = true, example = "789012")
    @Parameter(name = "tag", description = "操作标签（如：点赞、收藏、评论、分享）", required = true, example = "like")
    @Parameter(name = "status", description = "状态（如：0-取消，1-操作）", required = true, example = "1")
    @PermitAll
    public CommonResult<DebatehallDO> operate(
            @RequestParam("userId") Long userId,
            @RequestParam("debateId") Long debateId,
            @RequestParam("tag") String tag,
            @RequestParam("status") Integer status) {
        DebatehallDO operate = debatehallService.operate(userId, debateId, tag, status);
        return success(operate);
    }


    @GetMapping("/get")
    @Operation(summary = "获取详情信息")
    @Parameter(name = "id", description = "编号", required = true, example = "29")
    @PermitAll
    public CommonResult<DebatehallDO> getUser(@RequestParam("id") Long id) {
        DebatehallDO data = debatehallService.get(id);
        return success(data);
    }


    @PostMapping("commentsave")
    @Operation(summary = "新增评论")
    public CommonResult<DebatehallCommentDO> saveComment(@RequestBody DebatehallCommentDO dto){
        DebatehallCommentDO debatehallCommentDO = debatehallCommentService.insertComment(dto);
        return success(debatehallCommentDO);
    }
    @GetMapping("/operatecomment")
    @Operation(summary = "评论信息点赞")
    @Parameter(name = "userId", description = "用户编号", required = true, example = "123456")
    @Parameter(name = "commentId", description = "评论编号", required = true, example = "789012")
    @Parameter(name = "status", description = "状态（如：0-取消，1-点赞）", required = true, example = "1")
    @PermitAll
    public CommonResult<String> operatecomment(
            @RequestParam("userId") Long userId,
            @RequestParam("commentId") Long commentId,
            @RequestParam("status") Integer status) {
        debatehallService.operatecomment(userId, commentId, status);
        return success("ok");
    }
}